/**
 * 发出请求，返回Promise对象
 * @param {string} url 请求地址
 * @param {object} options 请求参数
 * @param {number} retryCount 重试次数
 */

function request(url, options, retryCount = 3) {
  return fetch(url).catch((error) => {
    console.log("开启重试", retryCount);
    return retryCount <= 0
      ? Promise.reject(error)
      : request(url, options, retryCount - 1);
  });
}

let url = "https://my-json-server.typicode.com/typicode/demo/posts";
// url = "https://my-json-server.typicode.com/typicode/demo/profile";
// url = "https://www.baidu.com";
url = "https://my-json-seer.typicode.com/112/demo/posts/123";
request(url, {}, 3)
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.error(err);
  });
